﻿using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Caching.Redis;
using Microsoft.Extensions.DependencyInjection;
using System;
using Volo.Abp.Caching;
using Volo.Abp.Modularity;

namespace Radis.Application.Caching
{
    public class ProductContext
    {
        class EcomerceApplicationCachingModule
        {
            [DependsOn(typeof(AbpCachingModule))
        ]
            public class ProductContext : AbpModule
            {
                public override void ConfigureServices(ServiceConfigurationContext context)
                {
                    //从appsetting.json里面取数据库链接
                    var configuration = context.Services.GetConfiguration();
                    var RedisConnCtionString = configuration["Caching:RedisConnectionString"];
                    context.Services.AddStackExchangeRedisCache(options =>
                    {
                        options.Configuration = RedisConnCtionString;
                    });
                    //需引用包Nuget包  caching.csredis
                    var csredis = new CSRedis.CSRedisClient(RedisConnCtionString);
                    RedisHelper.Initialization(csredis);

                    context.Services.AddSingleton<IDistributedCache>(new CSRedisCache(RedisHelper.Instance));
                }
            }
        }
    }
}
